package com.itheima.reggie.mapper;

import com.itheima.reggie.dto.SetmealDto;
import com.itheima.reggie.entity.Setmeal;
import org.apache.ibatis.annotations.*;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @Author: qingtao
 * @Date 2022/3/10 12:09
 */
public interface SetmealMapper {
    /**
     * 查看是否有关联套餐
     * @param id
     * @return
     */
    @Select("select COUNT(*) from setmeal where category_id=#{id} and is_deleted=0")
    Long findSetMealByCategoryId(Long id);

    /**
     * 根据孟子查询
     * @param name
     * @return
     */
    List<Setmeal> findAllByName(String name);

    /**
     * 添加
     * @param setmealDto
     * @return
     */
    @Insert("insert into setmeal values (null,#{categoryId},#{name},#{price},#{status},#{code}," +
            "#{description},#{image},#{createTime},#{updateTime},#{createUser},#{updateUser},0);")
    @Options(useGeneratedKeys = true,keyColumn = "id",keyProperty = "id")
    Integer save(SetmealDto setmealDto);


    /**
     * 条件查询
     * @param name
     * @return
     */
    @Select("select * from setmeal where `name`=#{name}")
    Setmeal findByName(String name);

    /**
     * 查询起售状态
     * @param ids
     * @return
     */
    Integer findByStatus(@Param("ids") List<Long> ids);

    /**
     * 伪删除
     * @param ids
     * @return
     */
    Integer delete(@Param("ids") List<Long> ids,
                   @Param("updateUser") Long updateUser,
                   @Param("updateTime") LocalDateTime updateTime);

    /**
     * 修改状态
     * @param ids
     * @param status
     * @return
     */
    Integer updateStatus(@Param("ids") List<Long> ids,
                         @Param("status") Integer status,
                         @Param("updateUser") Long updateUser,
                         @Param("updateTime") LocalDateTime updateTime);

    /**
     * 修改
     * @param setmealDto
     * @return
     */
    Integer update(SetmealDto setmealDto);

    /**
     * 根据Id查找
     * @param id
     * @return
     */
    @Select("select * from setmeal where id=#{id}")
    Setmeal findById(Long id);

    /**
     * 根据套餐的类别展示套餐
     * @param categoryId
     * @param status
     * @return
     */
    @Select("select * from setmeal where category_id=#{categoryId} and status=#{status}")
    List<Setmeal> list(@Param("categoryId") Long categoryId,@Param("status") Integer status);

}
